[#include "../../dbadminer/common/html.ftl" /]
[@html]
    [@head title="操作日志列表" css=["fw", "bootstrap-table"] /]
    [@body]
        [#--主体内容--]
        [@main ]
            <div class="am-g am-radius fw-tables">
                [#--表格主体内容--操作栏--]
                [@mainHeader /]

                [#--表格主体内容--搜索栏--]
                [@searchForm searchId="form-operlog-search" ]
                    <div class="am-form-group">
                        <input type="text" name="connectName" class="am-form-field am-input-sm am-radius" placeholder="操作人员">
                    </div>
                    <div class="am-form-group">
                        <input type="text" name="databaseName" class="am-form-field am-input-sm am-radius" placeholder="操作人员">
                    </div>
                    <div class="am-form-group">
                        <input type="text" name="operUserName" class="am-form-field am-input-sm am-radius" placeholder="操作人员">
                    </div>
                    <div class="am-form-group">
                        <input id="deptTreeId" name="deptId" type="hidden"/>
                        <input  id="deptTreeName" type="text" name="deptName" class="am-form-field am-input-sm am-radius"
                                placeholder="部门名称" onclick="choiceDeptTree('33','deptTreeId','deptTreeName')">
                    </div>
                    <div class="am-form-group">
                        <select name="operType" class="am-radius" data-am-selected placeholder="操作类型">
                            <option value=""></option>
                            [#list dict.getType("dba_oper_type") as dict]
                                <option value="${dict.dictValue}">${dict.dictLabel}</option>
                            [/#list]
                        </select>
                    </div>
                    <div class="am-form-group">
                        <select name="execStatus" class="am-radius" data-am-selected placeholder="执行状态">
                            <option value=""></option>
                            [#list dict.getType("sys_common_status") as dict]
                                <option value="${dict.dictValue}">${dict.dictLabel}</option>
                            [/#list]
                        </select>
                    </div>
                    <div class="am-form-group">
                        <div class="am-form-group am-form-icon">
                            <i class="am-icon-calendar"></i>
                            <input type="text" name="params[beginTime]" class="am-form-field am-input-sm am-radius" placeholder="操作时间-开始"
                                   data-am-datepicker readonly/>
                        </div>
                        <div class="am-form-group am-form-icon">
                            <i class="am-icon-calendar"></i>
                            <input type="text" name="params[endTime]" class="am-form-field am-input-sm am-radius" placeholder="操作时间-结束"
                                   data-am-datepicker readonly/>
                        </div>
                    </div>
                [/@searchForm]

                <div class="fw-table">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        [/@main]

        [#--PC/APP 右侧悬浮按钮--]
        [@rightToolbar /]

        [@script js=["fw", "bootstrap-table", "ztree-ajax"]]
            <script type="text/javascript">
                var prefix = ctx + "osfw/dbadminer/operlog";
                var operTypeDatas = ${convert.toJson(dict.getType("dba_oper_type"))};
                var commonStatusDatas = ${convert.toJson(dict.getType("sys_common_status"))};

                $(function () {
                    var options = {
                        url: prefix + "/list",
                        exportUrl: prefix + "/export",
                        modalName: "操作日志",
                        rememberSelected: true,
                        uniqueId: "operId",
                        sortName: "operTime",
                        sortOrder: "desc",
                        columns: [
                            {
                                // field: 'state',
                                checkbox: true
                            },
                            {
                                title: "序号",
                                formatter: function (value, row, index) {
                                    return $.table.serialNumber(index);
                                }
                            },
                            {
                                field: 'connectName',
                                title: '连接名称'
                            },
                            {
                                field: 'databaseName',
                                title: '数据库'
                            },
                            {
                                field: 'datatableName',
                                title: '数据表/视图'
                            },
                            {
                                field: 'operType',
                                title: '操作类型',
                                formatter: function (value, row, index) {
                                    return $.table.selectDictLabel(operTypeDatas, value);
                                }
                            },
                            {
                                field: 'operUserName',
                                title: '操作人员'
                            },
                            {
                                field: 'operDeptName',
                                title: '操作部门',
                                visible: false,
                            },
                            {
                                field: 'operIp',
                                title: '操作地址',
                                visible: false,
                            },
                            {
                                field: 'operLocation',
                                title: '操作地点',
                                visible: false,
                            },
                            {
                                field: 'operTime',
                                title: '操作时间'
                            },
                            {
                                field: 'isApproval',
                                title: '是否审批',
                                formatter: function (value, row, index) {
                                    if (value == 0) {
                                        return '<span class="am-badge am-badge-transparent am-radius" style="color: black!important;">否</span>';
                                    } else if (value == 1) {
                                        return '<a class="am-badge am-badge-transparent am-radius" href="javascript:void(0)" onclick="approvalDetail(\'' + row.actProcinstI + '\')" title="查看详情">是</a>';
                                    }
                                }
                            },
                            {
                                field: 'execStmt',
                                title: '执行语句',
                                formatter: function (value, row, index) {
                                    return '<a class="am-badge am-badge-transparent am-radius" href="javascript:void(0)" onclick="showSql(\'' + value + '\')" title="查看详情">SQL</a>';
                                }
                            },
                            {
                                field: 'execTime',
                                title: '执行时间',
                                sortable: true
                            },
                            {
                                field: 'costTime',
                                title: '执行耗时',
                                visible: false,
                                formatter: function (value, row, index) {
                                    return value ? (value/1000) + "s" : "--";
                                }
                            },
                            {
                                field: 'execStatus',
                                title: '执行状态',
                                align: 'left',
                                formatter: function (value, row, index) {
                                    return $.table.selectDictLabel(commonStatusDatas, value);
                                }
                            },
                            {
                                field: 'execResult',
                                title: '执行结果',
                                visible: false,
                                formatter: function (value, row, index) {
                                    return '<a class="am-badge am-badge-transparent am-radius" href="javascript:void(0)" onclick="showResult(\'' + value + '\')" title="查看详情">RESULT</a>';
                                }
                            }]
                    };
                    $.table.init(options);
                });


                function approvalDetail(procInstId) {
                    $.modal.alertSuccess("审批信息");
                }

                function showResult(result) {
                    $.modal.alertSuccess("执行结果");
                }

            </script>
        [/@script]
    [/@body]
[/@html]
